package com.origon.entities;

import java.io.Serializable;
import static javax.persistence.CascadeType.ALL;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;


/**
 * The persistent class for the user database table.
 * 
 */
@Entity
public class User implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	
	private String id;

	private String activationKey;

	private String cellPhoneNumber;

	private String email;

	private String failedLogins;

	private String firstname;

	private String gender;

	private String lastname;

	private Boolean locked;

	private String password;

	private Boolean privacyPolicy;

	private Timestamp registrationDate;

	private String telephoneNumber;

	private Boolean termsAndCondition;

	private String username;

	//bi-directional many-to-one association to Bid
	@OneToMany(mappedBy="user")
	private List<Bid> bids;

	//bi-directional many-to-one association to Inbox
	@OneToMany(mappedBy="user")
	private List<Inbox> inboxs;

	//bi-directional many-to-one association to Mail
	@OneToMany(mappedBy="user")
	private List<Mail> mails;

	//bi-directional many-to-one association to Sale
	@OneToMany(mappedBy="user")
	private List<Sale> sales;

	//bi-directional many-to-one association to Shop
	@OneToMany(mappedBy="user")
	private List<Shop> shops;

	//bi-directional many-to-one association to Address
	@ManyToOne(fetch = FetchType.LAZY, cascade=ALL)
	@JoinColumn(name="BillingAddressId")
	private Address billingAddress;

	//bi-directional many-to-one association to Address
	@ManyToOne(fetch = FetchType.LAZY, cascade=ALL)
	@JoinColumn(name="ShippingAddressId")
	private Address shippingAddress;

	//bi-directional many-to-one association to Country
	@ManyToOne
	@JoinColumn(name="CountryId")
	private Country country;

	//bi-directional many-to-one association to Language
	@ManyToOne
	@JoinColumn(name="LanguageId")
	private Language language;

	//bi-directional many-to-many association to Mail
	@ManyToMany
	@JoinTable(
		name="outbox"
		, joinColumns={
			@JoinColumn(name="UserId")
			}
		, inverseJoinColumns={
			@JoinColumn(name="MailId")
			}
		)
	private List<Mail> mails2;

	//bi-directional many-to-many association to Role
	@ManyToMany
	@JoinTable(
		name="userrole"
		, joinColumns={
			@JoinColumn(name="UserId")
			}
		, inverseJoinColumns={
			@JoinColumn(name="RoleId")
			}
		)
	private List<Role> roles;

	public User() {
		setId(UUID.randomUUID().toString());
	}

	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getActivationKey() {
		return this.activationKey;
	}

	public void setActivationKey(String activationKey) {
		this.activationKey = activationKey;
	}

	public String getCellPhoneNumber() {
		return this.cellPhoneNumber;
	}

	public void setCellPhoneNumber(String cellPhoneNumber) {
		this.cellPhoneNumber = cellPhoneNumber;
	}

	public String getEmail() {
		return this.email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getFailedLogins() {
		return this.failedLogins;
	}

	public void setFailedLogins(String failedLogins) {
		this.failedLogins = failedLogins;
	}

	public String getFirstname() {
		return this.firstname;
	}

	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}

	public String getGender() {
		return this.gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public String getLastname() {
		return this.lastname;
	}

	public void setLastname(String lastname) {
		this.lastname = lastname;
	}

	public Boolean getLocked() {
		return this.locked;
	}

	public void setLocked(Boolean locked) {
		this.locked = locked;
	}

	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Boolean getPrivacyPolicy() {
		return this.privacyPolicy;
	}

	public void setPrivacyPolicy(Boolean privacyPolicy) {
		this.privacyPolicy = privacyPolicy;
	}

	public Timestamp getRegistrationDate() {
		return this.registrationDate;
	}

	public void setRegistrationDate(Timestamp registrationDate) {
		this.registrationDate = registrationDate;
	}

	public String getTelephoneNumber() {
		return this.telephoneNumber;
	}

	public void setTelephoneNumber(String telephoneNumber) {
		this.telephoneNumber = telephoneNumber;
	}

	public Boolean getTermsAndCondition() {
		return this.termsAndCondition;
	}

	public void setTermsAndCondition(Boolean termsAndCondition) {
		this.termsAndCondition = termsAndCondition;
	}

	public String getUsername() {
		return this.username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public List<Bid> getBids() {
		return this.bids;
	}

	public void setBids(List<Bid> bids) {
		this.bids = bids;
	}

	public Bid addBid(Bid bid) {
		getBids().add(bid);
		bid.setUser(this);

		return bid;
	}

	public Bid removeBid(Bid bid) {
		getBids().remove(bid);
		bid.setUser(null);

		return bid;
	}

	public List<Inbox> getInboxs() {
		return this.inboxs;
	}

	public void setInboxs(List<Inbox> inboxs) {
		this.inboxs = inboxs;
	}

	public Inbox addInbox(Inbox inbox) {
		getInboxs().add(inbox);
		inbox.setUser(this);

		return inbox;
	}

	public Inbox removeInbox(Inbox inbox) {
		getInboxs().remove(inbox);
		inbox.setUser(null);

		return inbox;
	}

	public List<Mail> getMails() {
		return this.mails;
	}

	public void setMails(List<Mail> mails) {
		this.mails = mails;
	}

	

	public List<Sale> getSales() {
		return this.sales;
	}

	public void setSales(List<Sale> sales) {
		this.sales = sales;
	}

	public Sale addSale(Sale sale) {
		getSales().add(sale);
		sale.setUser(this);

		return sale;
	}

	public Sale removeSale(Sale sale) {
		getSales().remove(sale);
		sale.setUser(null);

		return sale;
	}

	public List<Shop> getShops() {
		return this.shops;
	}

	public void setShops(List<Shop> shops) {
		this.shops = shops;
	}

		

	public Address getBillingAddress() {
		return billingAddress;
	}

	public void setBillingAddress(Address billingAddress) {
		this.billingAddress = billingAddress;
	}

	public Address getShippingAddress() {
		return shippingAddress;
	}

	public void setShippingAddress(Address shippingAddress) {
		this.shippingAddress = shippingAddress;
	}

	public Country getCountry() {
		return this.country;
	}

	public void setCountry(Country country) {
		this.country = country;
	}

	public Language getLanguage() {
		return this.language;
	}

	public void setLanguage(Language language) {
		this.language = language;
	}


	@ManyToMany(cascade = { CascadeType.ALL })
    @JoinTable(name = "UserRole", joinColumns = { @JoinColumn(name = "UserId") }, inverseJoinColumns = { @JoinColumn(name = "RoleId") })
	public List<Role> getRoles() {
		if(this.roles == null)
		{
			roles = new ArrayList<Role>();
		}
		return this.roles;
	}

	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}

}